<!-- 季度考核-监控 -->
<template>
  <div>
    <!--引用表格-->
    <BasicTable @register="registerTable" :rowSelection="rowSelection">
    </BasicTable>
  </div>
</template>

<script lang="ts" name="emp-team-checkIn3-HubTeamResultMonitoring" setup>
import { ref, onMounted, reactive, provide, } from 'vue';

import { BasicTable, TableAction } from '/@/components/Table';
import { useModal } from '/@/components/Modal';
import { useListPage } from '/@/hooks/system/useListPage'
import { columns, searchFormSchema } from './HubTeamMonitorData';
import { getPeriodTree } from '/@/api/common/api';
import { render } from '/@/utils/common/renderUtils';
import { initDictOptions } from '/@/utils/dict/index';
import { list, reEvaluate, getColumn } from './resultApi';
import { useRouter } from 'vue-router';
import { cloneDeep } from 'lodash-es';
import dayjs from 'dayjs';

const queryParam = reactive<any>({});
//注册model
const [registerModal, { openModal }] = useModal();
//注册table数据
const { tableContext, onExportXls, onImportXls } = useListPage({
  tableProps: {
    title: '系统数据库表',
    api: list,
    columns,
    canResize: false,
    showIndexColumn: true,
    formConfig: {
      //labelWidth: 120,
      schemas: searchFormSchema,
      autoSubmitOnEnter: true,
      showAdvancedButton: true,
      fieldMapToNumber: [],
      fieldMapToTime: [],
    },
    actionColumn: {
      width: 240,
      fixed: 'right'
    },
    beforeFetch: (params) => {
      // params.pageSize = 20;
      return Object.assign(params, queryParam);
    },
  },
});

const [registerTable, { getForm, reload, getDataSource, setTableData }, { rowSelection, selectedRowKeys }] = tableContext;


const tableRef = ref(null);
const router = useRouter();
const status = '20';
const statusOptionsList = ref([]);


// 默认执行一次
onMounted(async () => {
  statusOptionsList.value = await initDictOptions('epm_team_resultType');
  getForm().updateSchema([
    {
      field: 'status',
      label: '提交状态',
      component: 'Select',
      componentProps: {
        options: statusOptionsList,
        immediate: true,
        onChange: (e) => {
        },
        fieldNames: {
          label: 'text',
          value: 'value',
        },
        onOptionsChange: (options) => {
          // console.log('get options', options.length, options);
        },
      },
      colProps: { span: 8 },
    },
  ]);
});

const save = (saveData) => {
  saveData.datas.forEach((item) => {
    item.status = '0';
  });
  reEvaluate(saveData).then(() => {
    reload();
  });
};

//查询动态表头
function getTableColumn(params) {
  return new Promise((resolve) => {
    getColumn(params).then((res) => {
      let newColumn = [...columns];
      res.forEach((r) => {
        let temp = {
          title: r.headName,
          dataIndex: r.headCode,
          width: 200,
          align: 'center',
        };
        // 平衡系数
        if ('hortationScore' === r.headCode) {
          //temp.editRow = true;
          temp.editComponent = 'InputNumber';
          showEdit.value = true;
        }
        // 等级
        if ('grade' === r.headCode) {
          //temp.editRow = true;
          temp.editComponent = 'Select';
          showEdit.value = true;
        }
        newColumn.splice(newColumn.length - 2, 0, {
          ...temp,
          checkDetail: r.checkDetail, //判断是否能打开详情 boolean
          scopedSlots: { customRender: r.headCode },
        });
      });
      newColumn[newColumn.length - 2]['fixed'] = 'right';
      newColumn[newColumn.length - 1]['fixed'] = 'right';
      resolve(newColumn);
    });
  });
}
</script>